// 存放接口 定义各种接口方法
// 接口方法, 只负责调用一个接口, 返回一个Promise对象
import request from '@/utils/request.js'
// 引入vuex
import store from '@/store'
export const allChannelListAPI = () => {
  return request({
    url: '/v1_0/channels'
  })
}
// 登录接口
// export const loginAPI = ({ mobile, code }) => {
//   return request({
//     url: '/v1_0/authorizations',
//     method: 'POST',
//     data: {
//       mobile, code
//     }
//   })
// }
export const loginAPI = (data) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}
// 头部导航栏接口
export const userChannelAPI = () => {
  return request({
    url: '/v1_0/user/channels'
    // headers请求头 字符串拼接
    // headers: {
    //   Authorization: 'Bearer' + store.state.token
    // }
  })
}
// 获取新闻列表数据
export const articlesListAPI = ({ channel_id, timestamp }) => {
  return request({
    url: '/v1_0/articles',
    // params参数 get里 这样写  POST里面用data
    params: {
      channel_id,
      timestamp: timestamp || (new Date()).getTime()
    }
  })
}
// 对文章不喜欢
export const articleDislikeAPI = ({ target }) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'POST',
    data: {
      target
    }
    // headers: {
    //   Authorization: 'Bearer ' + store.state.token
    // }
  })
}
// 举报文章
export const articleReportsAPI = ({ target, type, remark }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: target,
      type: type,
      remark: remark
    },
    headers: {
      Authorization: 'Bearer ' + store.state.token
    }
  })
}
// 频道 - 更新已选
export const updateChannelAPI = ({ channels }) => {
  return request({
    url: '/v1_0/user/channels',
    method: 'PUT',
    data: {
      channels: channels
    }
  })
}
// 搜索 - 联想菜单
export const suggestListAPI = ({ q }) => {
  return request({
    url: '/v1_0/suggestion',
    params: {
      q: q
    }
  })
}
